﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class voice_recording_record_exist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Request.Params["file"] != null)
            {
                divExist.Visible = true;
                Session["LastFileName"] = null;
                hplDownload2.NavigateUrl = "~/voice-recording/" + Request.Params["file"].ToString().Split(new string[] { "voice-recording" }, StringSplitOptions.None)[1];
                hplDownload2.Text = "Your last recorded file";
            }
        }
        catch (Exception Ex)
        {
            CreateExceptionLog(Ex, "Page_Load");
        }
    }

    private static void CreateExceptionLog(Exception Ex, string strLocation)
    {
        String[] _fileContent = new String[7];
        _fileContent[1] = "Source : " + Ex.Source;
        _fileContent[2] = "Date Time : " + DateTime.Now.ToString();
        _fileContent[3] = "Stack Trace :" + Ex.StackTrace.ToString();
        _fileContent[4] = "Target Site : " + Ex.TargetSite.ToString();
        _fileContent[5] = "Location : " + "MyMailManager - " + strLocation;
        _fileContent[6] = "Message : " + Ex.Message;

        WriteExceptionLog("Ex_", _fileContent);
    }

    private static void WriteExceptionLog(string strPrefixFileName, string[] strException)
    {
        try
        {
            CE.InputOut.MyIO _newFile = new CE.InputOut.MyIO();
            string _filePath = AppDomain.CurrentDomain.BaseDirectory + "Exception\\";
            if (_newFile.CheckDirectory(_filePath))
            {
                string _curMonth = DateTime.Now.Year.ToString("0000") + DateTime.Now.Month.ToString("00");

                if (!_newFile.CheckDirectory(_filePath + _curMonth))
                {
                    if (_newFile.CreateDirectory(_filePath, _curMonth))
                    {
                        _filePath += _curMonth + "\\";
                    }
                }
                else
                {
                    _filePath += _curMonth + "\\";
                }

                string _fileName = strPrefixFileName + _curMonth + DateTime.Now.Day.ToString("00") + DateTime.Now.Second.ToString("00") + DateTime.Now.Millisecond.ToString("00") + ".txt";

                _newFile.WriteNewFile(_filePath, _fileName, strException);
                _newFile = null;
            }
        }
        catch (Exception Ex)
        {
            Ex = null;
        }
    }

    protected void btnRecordNew_Click(object sender, EventArgs e)
    {
        Response.Redirect("default.aspx?fileoverwrite=" + Request.Params["file"].ToString());
    }
}
